package com.top.ruizhong.main.host

import com.blankj.utilcode.util.ConvertUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.module.lemlin.base.BaseAbstractFragment
import com.module.lemlin.custom.SpacingItemDecoration
import com.top.ruizhong.R
import com.top.ruizhong.main.goods.GoodsDetailsActivity
import kotlinx.android.synthetic.main.fragment_search_goods.*

class SearchGoodsFragment : BaseAbstractFragment() {

    companion object {
        fun newInstance(): SearchGoodsFragment {
            return SearchGoodsFragment()
        }
    }

    private val cateGoodsAdapter =
        object : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_goods_category) {
            override fun convert(holder: BaseViewHolder, item: String) {
            }
        }

    override val layoutResId: Int
        get() = R.layout.fragment_search_goods

    override fun initView() {

        //初始化物品列表视图
        rvSearchGoodsBody.apply {
            val decoration = SpacingItemDecoration(
                vGap = ConvertUtils.dp2px((15f)),
                hGap = ConvertUtils.dp2px((15f))
            )
            addItemDecoration(decoration)
        }.adapter = cateGoodsAdapter.apply {
            setOnItemClickListener { _, _, _ ->
                GoodsDetailsActivity.open(requireActivity())
            }
        }
    }

    override fun initData() {
        val goods: MutableList<String> = mutableListOf()
        for (index in 0..10) {
            goods.add(index.toString())
        }
        cateGoodsAdapter.setNewInstance(goods)
    }

}